package com.wkq.net

import android.content.Context
import java.io.File

/**
 *
 *@Author: wkq
 *
 *@Time: 2025/4/8 17:06
 *
 *@Desc: 网络请求配置
 */
class RetrofitNetConfig private constructor() {
    private var mHeader:HashMap<String,String>?=null
    private  var baseUrl:String?=null
    private  var isDebug:Boolean?=false
    companion object {
        @Volatile
        private var instance: RetrofitNetConfig? = null

        fun getInstance(): RetrofitNetConfig {
            if (RetrofitNetConfig.instance == null) {
                synchronized(RetrofitRequestHelper::class) {
                    if (RetrofitNetConfig.instance == null) {
                        RetrofitNetConfig.instance = RetrofitNetConfig()
                    }
                }
            }
            return RetrofitNetConfig.instance!!
        }
    }

    /**
     * 初始化 Header
     * @param baseUrl String?
     * @param header HashMap<String, String>?
     */
    fun init(baseUrl:String?,mHeader:HashMap<String,String>?,isDebug:Boolean?=false){
        this.baseUrl=baseUrl
        this.mHeader=mHeader
        this.isDebug=isDebug
    }
    fun getNetHeader():HashMap<String,String>?{
        return mHeader
    }

    fun updateNetHeader(key : String,values: String){
        mHeader?.put(key,values)
    }

    fun getNetBaseUrl():String?{
        return baseUrl
    }
    fun isNetDebug():Boolean?{
        return isDebug
    }
    fun getCacheDownFilePath(context:Context):String{
        val cacheDirectory = context.cacheDir.absolutePath+ File.separator+"VoiceDownFile"
        if (!File(cacheDirectory).exists()){
            File(cacheDirectory).mkdir()
        }
        return context.cacheDir.absolutePath+ File.separator+"VoiceDownFile"
    }
}